import { request ,callService } from './request.js'
// import { handleErrorCode } from '@/util/common/message.js'

export async function onGotApiData(apiUrl, method, params, callback) {
	await request({
		url: apiUrl,
		method: method,
		data: params,
		withCredentials: true,
	}).then(res => {
		console.log("api请求成功",res)
		callback && callback(res);
	}).catch(function(error) {
		console.log('捕捉到了错误',error)
	});
}

export async function GotApiData(apiUrl, method, params, callback) {
	await request({
		url: apiUrl,
		method: method,
		data: params,
		withCredentials: true,
	}).then(res => {
		console.log("api请求成功",res)
		callback && callback(res);
	}).catch(function(error) {
		console.log('捕捉到了错误',error)
	});
}

//统计事件
export async function addClick(key, key2, key3) {
	let channel_no = uni.getStorageSync('EK_channel_no')
	return new Promise((resolve, reject) => {
		uni.request({
			url: 'https://dysx-api.ksbmtb.com:8889/api/event/add', //仅为示例，并非真实接口地址。
			method: "POST",
			data: {
				page_name: key,
				version_number: key2,
				channel_no:channel_no,
				platform:'H5',
				event_name: key3,
			},
			header: {
				'content-type': 'application/x-www-form-urlencoded' //自定义请求头信息
			},
			success: async (res) => {
				resolve(res.result)
			}
		});
	});
}

export async function getService(apiUrl, method, params, callback) {
	await callService({
		url: apiUrl,
		method: method,
		data: params,
		withCredentials: true,
	}).then(res => {
		console.log("api请求成功",res)
		callback && callback(res);
	}).catch(function(error) {
		console.log('捕捉到了错误',error)
	});
}
